const net = require("net");

const server = net.createServer();
const PORT = 1234;
const HOST = "127.0.0.1";
server.listen(PORT, HOST);
server.on("listening", () => {
  console.log(`服务器运行在 http://${HOST}:${PORT}/`);
});

server.on("connection", (socket) => {
  socket.on("data", (data) => {
    const msg = data.toString();
    console.log(msg);

    socket.write(Buffer.from("Hello " + msg));
  });
});

server.on("error", (err) => {
  console.log(err);
});
server.on("close", () => {
  console.log("Server closed");
});
